<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/css/font.css">
<link rel="stylesheet" href="/css/index.css">
<script type="text/javascript" src="/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/index.js"></script>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/layui-post.js"></script>
</head>
<body>
<div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body layui-table-body layui-table-main">
                <table class="layui-table layui-form" id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</div>
</body>
<script>
$.ajaxSetup({contentType: "application/json; charset=utf-8"});
layui.use(['table','form'], function(){
	var table = layui.table
    $.post(geturl()+'/cateringUser/select?token='+sessionStorage.getItem("token"), JSON.stringify({}), function (res) {
        for(var i in res.data) $('#userId').append('<option value="'+res.data[i].userId + '">' + res.data[i].nickName + '</option>');
        layui.form.render();
    })
    $.post(geturl()+'/enums/select?token='+sessionStorage.getItem("token"), JSON.stringify({parentEnumCode:"DELIVERY_TYPE<->ORDER_STATUS",orderByAscType:"enumCode"}), function (res) {
        for(var key in res.data.DELIVERY_TYPE) $('#sendType').append('<option value="'+key + '">' + res.data.DELIVERY_TYPE[key] + '</option>');
        layui.form.render();
    }).done(function(res){
        function enums(s,enumCode){
            for(var key in res.data[enumCode]) if(key === s) return res.data[enumCode][s];
        }
        table.render({
            elem: 'table', //指定元素
            url:geturl()+'/cateringOrderLog/select?token='+sessionStorage.getItem("token"),
            contentType:'application/json',
            method:'post',
            page:false,
            cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            where:{orderByAscType: "createTime",orderId:getQueryString("sysId")},
            cols: [[
                //{type: 'checkbox',width: 80},
                {title: '序号',align:"center",halign:"center",width:80,type: 'numbers'},
                {field:'orderStatus',align:"center",title:'当前状态',templet: function(d){return enums(d.orderStatus,"ORDER_STATUS")}},
                {field:'createTime',align:"center",title: '节点时间',},
                //{fixed:'right',align: 'center',title:'操作',width: 100,templet: onloadTool }
            ]],
        });
    })
    layui.form.on('switch(switchTest)', function(data){
        var id = data.elem.attributes['data_id'].nodeValue;
        var status = data.elem.attributes['status'].nodeValue;
        var em = $(data.othis[0]);
        layer.confirm('确认'+(status == 0 ? '' : '取消')+'禁用吗？',{icon: 0,title:'提示',cancel:function(){closeSwitch1(data,status,em);}},function(index){
            if(status == 0) layuiPost(geturl()+'/cateringOrder/update?token='+sessionStorage.getItem("token"),{status:1,sysId:id});
            else layuiPost(geturl()+'/cateringOrder/update?token='+sessionStorage.getItem("token"),{status:0,sysId:id});
        },function(index){
            closeSwitch1(data,status,em)
        });
    });
});
/*删除*/
function member_del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
    	layuiPost(geturl()+'/cateringOrder/delete?token='+sessionStorage.getItem("token"),{sysId:id});
    });
}

$('#search').on('click', function() {
	layui.table.reload('table', {
		page: {curr: 1},
		where : {
            orderNo:$("#orderNo").val(),
            userId:$("#userId").val(),
            sendType:$("#sendType").val(),
		},
	});
	return false;
});

function onloadTool(data) {
	let htmls = 
	  	'<a title="编辑" onclick="xadmin.open(\'编辑\',\'cateringorderedit?sysId='+data.sysId+'\')" href="javascript:;"><i class="layui-icon">&#xe642;</i></a>'+
	  	'<a title="删除" onclick="member_del(this,\''+data.sysId+'\')" href="javascript:;"><i class="layui-icon">&#xe640;</i></a>'
   	return htmls;
}
</script>
</html>